/*************************************************************************
	> File Name: B4091.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-03-11 11:11:32
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int candy(vector<int> &rate) {
    vector<int> cnt(rate.size(), 1);
    int len = rate.size();
    int min_ans = INT32_MAX - 1;
    while (1) {
        if (cnt[0] <= cnt[len - 1] && rate[0] > rate[len - 1]) cnt[0]++;
        if (cnt[len - 1] <= cnt[0] && rate[len - 1] > rate[0]) cnt[len - 1]++;
        for (int i = 0; i < len - 1; i++) {
            if (cnt[i] <= cnt[i + 1] && rate[i] > rate[i + 1]) cnt[i]++;
            if (cnt[i] >= cnt[i + 1] && rate[i] < rate[i + 1]) cnt[i + 1]++;
        }
        int res = 0;
        for (auto x : cnt) res += x;
        if (res == min_ans) return min_ans;
        min_ans = res;
    }
    return 0;
}

int main() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    cout << candy(arr) << endl;
    return 0;
}
